﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SocialPhotos.Models;

namespace SocialPhotos.Widgets.LatestPhotos
{
    public class LatestPhotoController : ILatestPhotoController
    {
        private readonly EfDbContext _efDbContext = new EfDbContext();
        public LatestPhotoViewModel GetViewModel (int size)
        {
            LatestPhotoViewModel viewModel = new LatestPhotoViewModel();

            var query = this._efDbContext.Photos.Select(p => p).OrderByDescending(p => p.Id).Take(size);
            viewModel.ModuleHeadText = "Latest photo uploaded";
            viewModel.LatestPhotoList = query.ToList();
            return viewModel;
        }
    }
}